<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>

<!DOCTYPE html>
<html class='no-js' lang='cn'>
  <jsp:include page="/head.jsp"/>
  <link rel="stylesheet" href="${ctx }/editor/lib/codemirror.css">
  <link rel="stylesheet" href="${ctx }/editor/addon/dialog/dialog.css">
  <link rel="stylesheet" href="${ctx }/editor/theme/monokai.css">
  
  <style type="text/css">
	.CodeMirror {
		border-top: 1px solid #eee;
		border-bottom: 1px solid #eee;
		font-size: 18px;
		height: auto; 
	}
	.CodeMirror-scroll { max-height: 500px; min-height: 100px;}
  </style>
  <body class='main page'>
  <jsp:include page="/top.jsp"/>
  
  <div id='wrapper'>
      <section id='tools'>
        <ul class='breadcrumb' id='breadcrumb'>
          <li class='title'>任务</li>
          <li class='active'>编辑</li>
        </ul>
      </section><!-- Sidebar -->
  <jsp:include page="/sidebar.jsp"/>
    	
     <!-- Content -->
     <div id='content'>
     	<form id="job_form">
     		<input type="hidden" name="jobType" value="${_jobType }" >
     		<input type="hidden" name="_id" value="${obj._id }" >
             <fieldset>
               <div class='form-group row'>
	               <div class='col-lg-10'>
	                 <label class='control-label'>名称</label>
	                 <input class='form-control' placeholder='输入任务名称 必须唯一 一旦定义不可改变' type='text' name="name" id="name" value="${obj.name }" ${obj._id!=null?"readonly='readonly'":"" }>
	               </div>
	                <div class='col-lg-2'>
	                   <label class='control-label'>状态</label>
	                   <select class="form-control" name="status">
	                    <option value="0" ${obj.status==0?"selected":"" }>停止</option>
						<option value="1" ${obj.status==1?"selected":"" }>运行</option>
	                   </select>
	                 </div>
               </div>
             </fieldset>
             
             
             <fieldset>
               <legend>参数配置</legend>
               <div class='form-group row'>
                 <!-- HTTP begin -->
                 <c:if test="${_jobType=='http' }">
                 <div class='col-lg-3'>
                   <label class='control-label'>采集深度</label>
                   <input class='form-control' placeholder='0不限制' type='text' name="depth" value="${obj.depth }">
                 </div>
                 <div class='col-lg-3'>
                   <label class='control-label'>线程数</label>
                   <input class='form-control' placeholder='默认为 1' type='text' name="threadNum" value="${obj.threadNum }">
                 </div>
                 <div class='col-lg-3'>
                   <label class='control-label'>采集方式</label>
                   <select class="form-control" name="rule">
                    <option value="width" ${obj.rule=="width"?"selected":"" }>广度优先</option>
                    <option value="depth" ${obj.rule=="depth"?"selected":"" }>深度优先</option>
                   </select>
                 </div>
                 <div class='col-lg-3'>
	               <label class='control-label'>保存html</label>
                   <select class="form-control" name="saveHtml">
                    <option value="false" ${!obj.saveHtml?"selected":"" }>不保存</option>
					<option value="true" ${obj.saveHtml?"selected":"" }>保存</option>
                   </select>
	              </div>
	              
	              <div class='col-lg-3'>
	               <label class='control-label'>自动抽取url</label>
                   <select class="form-control" name="parseUrl">
                    <option value="true" ${obj.parseUrl?"selected":"" }>抽取</option>
                    <option value="false" ${!obj.parseUrl?"selected":"" }>不抽取</option>
                   </select>
	              </div>
	              
	              <div class='col-lg-3'>
	               <label class='control-label'>错误重试次数</label>
                   <input class='form-control' placeholder='0为不重试' type='text' name="errCount" value="${obj.errCount }">
	              </div>
	              
	               <div class='col-lg-3'>
	               	<label class='control-label'>超时时间</label>
	               	<input class='form-control' placeholder='默认3000' type='text' name="timeout" value="${obj.timeout }">
	               </div>
	              
	              <div class='col-lg-3'>
	               <label class='control-label'>是否使用代理</label>
                   <select class="form-control" name="proxy">
                    <option value="false" ${!obj.proxy?"selected":"" }>不使用</option>
                    <option value="true" ${obj.proxy?"selected":"" }>使用</option>
                   </select>
	              </div>
	              
	              <div class='col-lg-12'>
	                 <label class='control-label'>正则过滤</label>
	                 <div style="float: right"><a id="regex_config"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></div>
	                 <textarea class='form-control' rows='4' id="regexFilter" name="regexFilter" >${obj.regexFilter }</textarea>
	               </div>
                </c:if>
                <!-- HTTP end -->
                <!-- DATA begin -->
                <c:if test="${_jobType=='data' }">
	                 <div class='col-lg-12'>
	                   <label class='control-label'>更新周期</label>
	                   <input class='form-control' placeholder='单位毫秒 0 为一次性结束' type='text' name="sleepTime" value="${obj.sleepTime }">
                	</div>
               </c:if>
               <!-- DATA END -->
               <!-- DIRECTORY begin -->
               <c:if test="${_jobType=='directory' }">
                 <div class='col-lg-3'>
                   <label class='control-label'>采集深度</label>
                   <input class='form-control' placeholder='0不限制' type='text' name="depth" value="${obj.depth }">
                 </div>
                 <div class='col-lg-3'>
                   <label class='control-label'>线程数</label>
                   <input class='form-control' placeholder='默认为 1' type='text' name="threadNum" value="${obj.threadNum }">
                 </div>
	              <div class='col-lg-12'>
	                 <label class='control-label'>正则过滤</label>
	                 <div style="float: right"><a id="regex_config_file"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></div>
	                 <textarea class='form-control' rows='4' id="regexFilter" name="regexFilter" >${obj.regexFilter }</textarea>
	               </div>
                </c:if>
                <!-- DIRECTORY end -->
                <!-- FTP begin -->
                <c:if test="${_jobType=='ftp' }">
                 <div class='col-lg-3'>
                   <label class='control-label'>采集深度</label>
                   <input class='form-control' placeholder='0不限制' type='text' name="depth" value="${obj.depth }">
                 </div>
                 <div class='col-lg-3'>
                   <label class='control-label'>线程数</label>
                   <input class='form-control' placeholder='默认为 1' type='text' name="threadNum" value="${obj.threadNum }">
                 </div>
	              
	              <div class='col-lg-3'>
	               <label class='control-label'>错误重试次数</label>
                   <input class='form-control' placeholder='0为不重试' type='text' name="errCount" value="${obj.errCount }">
	              </div>
	              
	               <div class='col-lg-3'>
	               	<label class='control-label'>超时时间</label>
	               	<input class='form-control' placeholder='默认3000' type='text' name="timeout" value="${obj.timeout }">
	               </div>
	              
	              <div class='col-lg-12'>
	                 <label class='control-label'>正则过滤</label>
	                 <div style="float: right"><a id="regex_config_file"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></div>
	                 <textarea class='form-control' rows='4' id="regexFilter" name="regexFilter" >${obj.regexFilter }</textarea>
	               </div>
                </c:if>
                <!-- FTP end -->
               </div>
             </fieldset>
             
             <fieldset>
               <legend>规则配置</legend>
               <div class='form-group'>
                  <label class='control-label'>输入</label>
                  <div style="float: right"><a id="input_config"><span class="glyphicon glyphicon-plus" ></span></a></div>
                  <textarea class='form-control' rows='4'  id="input" name="input">${obj.input }</textarea>
               </div>
               
               <div class='form-group'>
                 <label class='control-label'>解析</label>
                 <div style="float: right"><a onclick='$("#doc_api_table").toggle()'><span class="glyphicon glyphicon-plus"></span></a></div>
                 <table class="table table-bordered" id="doc_api_table" style="display: none">
	                  <thead>
					    <tr>
					      <th>名称</th>
					      <th>说明</th>
					      <th>例子</th>
					    </tr>
					  </thead>

	                  <tr class="success">
					    <td>内置对象</td>
					    <td><code>_doc</code>.(skipSave是否保存,<code>result</code>保存的结果,<code>document</code>网页解析对象Jsoup <code>html</code>:网页正文
					    <code>url</code>:当前网址<code>deep</code>:深度<code>fromUrl</code>:来源网址<code>)</td>
					    <td><code> _doc.skipSave = True ;</code></td>
					  </tr>
					  
					  <tr class="info">
					    <td rowspan="3" style="vertical-align:middle;">设置下一页</td>
					    <td><code>nextPage</code></td>
					    <td><code>_doc.nextPage="http://xxx/xxx.pageNo=3"</code></td>
					  </tr>
					   <tr class="info">
					    <td><code>void nextPage(String param, int step)</code></td>
					    <td><code>_doc.nextPage("pageNo", 1)</code></td>
					  </tr>
					  <tr class="info">
					    <td><code>void nextPageByTemplate(String template, int step)</code></td>
					    <td><code>_doc.nextPage("http://xxx{}xxx", 1)</code></td>
					  </tr>
					  
					  <tr class="success">
					    <td>抽取元素</td>
					    <td><code>void setValue(String key, String cssQuery, [String type :[string,int,double,data,float,long]])</code></td>
					    <td><code>_doc.setValue("title",".title")</code></td>
					  </tr>
					  
					  <tr class="info">
					    <td>抽取网址</td>
					    <td><code>void parseUrls( [String cssQuery])</code></td>
					    <td><code>_doc.parseUrls()</code></td>
					  </tr>
					  
					  <tr class="success">
					    <td>判断网址类型</td>
					    <td><code>boolean caseUrl(String regexId)</code></td>
					    <td><code>if _doc.caseUrl("xiangxi")</code></td>
					  </tr>
					  
				 </table>
                 <textarea class='form-control' rows='4' id="parse" id="parse" name="parse">${obj.parse==null?'#coding=utf-8':obj.parse }</textarea>
               </div>
               
               <div class='form-group'>
                 <label class='control-label'>输出</label>
                 <div style="float: right"><a id="output_config"><span class="glyphicon glyphicon-plus" ></span></a></div>
                 <textarea class='form-control' rows='4' id="output" id="output" name="output">${obj.output }</textarea>
               </div>
             </fieldset>
             
             <div class='form-actions text-right'>
               <button class='btn btn-success' type='button' id="reset_job">清空采集结果</button>
               <button class='btn btn-success' type='button' id="publish_job">提交</button>
               <button class='btn btn-info' type="button" id="test_job">测试</button>
             </div>
          </form>
          
          
         
     </div>
     
  </div>

  <!-- 正则表达式配置框 -->
  <div class="row className form-inline hidden" id="regexDomain">
		<fieldset>
			<div class="form-group row">
				<div class="col-lg-2">
					<label class="control-label">标识</label> 
					<input class="form-control" placeholder="取个名称可以重复" type="text" id="regexDomain_name">
				</div>
				<div class="col-lg-4">
					<label class="control-label">正则表达式</label> 
					<input class="form-control" placeholder="\d 任意数字 \s任意空格 \D非数字" type="text" id="regexDomain_regex">
				</div>
				<c:if test="${_jobType=='http' || _jobType=='directory' || _jobType=='ftp'}">
				  <div class="col-lg-2">
					<label class="control-label">状态</label> 
					<select class="form-control" id="regexDomain_flag">
						<option value="1">包含</option>
						<option value="0">不处理</option>
						<option value="2">不包含</option>
					</select>
				  </div>
				</c:if>
				<c:if test="${_jobType=='http'}">
				  <div class="col-lg-2">
					<label class="control-label">页面类型</label> 
					<select class="form-control" id="regexDomain_pageType">
						<option value="0">普通网页</option>
						<option value="1">列表页</option>
						<option value="2">内容页</option>
					</select>
				  </div>
				  <div class="col-lg-2">
					<label class="control-label">采集类型</label> 
					<select class="form-control" id="regexDomain_gatherType">
						<option value="0">普通网页</option>
						<option value="1">动态页面</option>
					</select>
				  </div>
				</c:if>
			</div>
		</fieldset>
	</div>
	
 <!-- 输入配置框 -->
  <div class="row className form-inline hidden" id="inputDomain">
	  <form class="form-horizontal" id="commonDiv">
		  
	</form>
</div>
	
<div id="inputTypeContainer" style="display: none;">
	 <div class="form-group" >
	   		<label class="col-sm-2 control-label">输入类型:</label>
	   		<div class="col-lg-2">
		        <select class="form-control" id="input_Type" onchange="selectInputType(this);">
						<option value="list">集合</option>
						<option value="file">文件</option>
						<option value="jdbc">jdbc</option>
						<option value="mongo">mongoDB</option>
						<option value="ftp">FTP</option>
						<option value="directory">directory</option>
				</select>
			</div>
	  </div>
	  <!-- 集合list -->
	  <div class="container-input-list" style="display: none;">
			  <div class="form-group" index="1">
			    <label class="col-sm-2 control-label">
				    <a id="add_input_list_id" onclick="addInputListUrl(this);"><span class="glyphicon glyphicon-plus" ></span></a>
			    </label>
			    <div class="col-sm-5">
			      <input class="form-control" placeholder="Url">
			    </div>
			  </div>
	  </div>
	  <!-- 文件输入 -->
	 <div class="container-input-file" style="display: none;">
		  		   <div class="form-group">
				   		<label class="col-sm-2 control-label">文件路径:</label>
				   		<div class="col-sm-5">
					      <input name="path" class="form-control" placeholder="Path">
					    </div>
				  </div>
				   <div class="form-group">
				   		<label class="col-sm-2 control-label">字符编码:</label>
				   		<div class="col-sm-5">
					      <input name="charEncoding" class="form-control" placeholder="CharEncoding">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">是否追加:</label>
				   		<div class="radio">
				   		&nbsp;&nbsp;&nbsp;
							  <label>
							    <input type="radio" name="append" id="appendRadio1" value="true" checked>
							   	是
							  </label>
							  &nbsp;
							  <label>
							    <input type="radio" name="append" id="appendRadio2" value="false">
							          否
							  </label>
						</div>
				  </div>
		  </div>
		  <!-- 数据源输入 -->
		  <div class="container-input-jdbc" style="display: none;">
		  		   <div class="form-group">
				   		<label class="col-sm-2 control-label">数据源地址:</label>
				   		<div class="col-sm-5">
					      <input name="jdbcUrl" class="form-control" placeholder="jdbcUrl">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">用户名:</label>
				   		<div class="col-sm-5">
					      <input name="username" class="form-control" placeholder="userName">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">密码:</label>
				   		<div class="col-sm-5">
					      <input name="password" class="form-control" placeholder="passWord">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">SQL语句:</label>
				   		<div class="col-sm-5">
					      <input name="sql" class="form-control" placeholder="sql">
					    </div>
				  </div>
				   <div class="form-group">
				   		<label class="col-sm-2 control-label">标志:</label>
				   		<div class="col-sm-5">
					      <input name="flag" class="form-control" placeholder="flag">
					    </div>
				  </div>
		  </div>
		  <!-- mongoDB输入 -->
		  <div class="container-input-db" style="display: none;">
		  		   <div class="form-group">
				   		<label class="col-sm-2 control-label">主机地址:</label>
				   		<div class="col-sm-5">
					      <input name="host" class="form-control" placeholder="host">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">端口:</label>
				   		<div class="col-sm-5">
					      <input name="port" class="form-control" placeholder="port">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">数据库名称:</label>
				   		<div class="col-sm-5">
					      <input name="dbName" class="form-control" placeholder="dbName">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">表名:</label>
				   		<div class="col-sm-5">
					      <input name="tableName" class="form-control" placeholder="tableName">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">查询条数:</label>
				   		<div class="col-sm-5">
					      <input name="batchSize" class="form-control" placeholder="batchSize">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">排序方法:</label>
				   		<div class="col-sm-5">
					      <input name="sortMethod" class="form-control" placeholder="sortMethod">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">标志名称:</label>
				   		<div class="col-sm-5">
					      <input name="flagName" class="form-control" placeholder="flagName">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">标志:</label>
				   		<div class="col-sm-5">
					      <input name="flag" class="form-control" placeholder="flag">
					    </div>
				  </div>
		  </div>
		  <!-- directory输入 -->
		  <div class="container-input-directory" style="display: none;">
		  		   <div class="form-group">
				   		<label class="col-sm-2 control-label">本地目录路径:</label>
				   		<div class="col-sm-5">
					      <input name="directory_path" class="form-control" placeholder="host">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">是否过滤隐藏文件:</label>
					    <div class="radio">
				   		&nbsp;&nbsp;&nbsp;
							  <label>
							    <input type="radio" name="append" id="isSkipHiddenRadio1" value="true" checked>
							   	是
							  </label>
							  &nbsp;
							  <label>
							    <input type="radio" name="append" id="isSkipHiddenRadio2" value="false">
							             否
							  </label>
						</div>
				  </div>
		  </div>
		  <!-- FTP输入 -->
		  <div class="container-input-ftp" style="display: none;">
		  		   <div class="form-group">
				   		<label class="col-sm-2 control-label">IP:</label>
				   		<div class="col-sm-5">
					      <input name="ftp_server" class="form-control" placeholder="IP">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">端口:</label>
				   		<div class="col-sm-5">
					      <input name="ftp_port" class="form-control" placeholder="port">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">用户名:</label>
				   		<div class="col-sm-5">
					      <input name="ftp_user" class="form-control" placeholder="user">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">密码:</label>
				   		<div class="col-sm-5">
					      <input name="ftp_password" class="form-control" placeholder="password">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">路径:</label>
				   		<div class="col-sm-5">
					      <input name="ftp_path" class="form-control" placeholder="path">
					    </div>
				  </div>
		  </div>
</div>
<div id="outputTypeContainer" style="display: none;">
	 <div class="form-group" id="outputTypeDiv" >
	   		<label class="col-sm-2 control-label">输出类型:</label>
	   		<div class="col-lg-2">
		        <select class="form-control" id="output_Type" onchange="selectOutputType(this);">
						<option value="console">控制台</option>
						<option value="file">文件</option>
						<option value="jdbc">JDBC</option>
						<option value="mongo">mongoDB</option>
				</select>
			</div>
	  </div>
	   <!-- 文件输出 -->
		  <div class="container-output-file" style="display: none;">
		  		  <div class="form-group">
				   		<label class="col-sm-2 control-label">文件路径:</label>
				   		<div class="col-sm-5">
					      <input name="path" class="form-control" placeholder="Path">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">字符编码:</label>
				   		<div class="col-sm-5">
					      <input name="charEncoding" class="form-control" placeholder="CharEncoding">
					    </div>
				  </div>
				   <div class="form-group">
				   		<label class="col-sm-2 control-label">文件最大:</label>
				   		<div class="col-sm-5">
					      <input name="max" class="form-control" placeholder="max">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">是否追加:</label>
				   		<div class="radio">
				   		&nbsp;&nbsp;&nbsp;
							  <label>
							    <input type="radio" name="append" id="appendRadio1" value="true" checked>
							   	是
							  </label>
							  &nbsp;
							  <label>
							    <input type="radio" name="append" id="appendRadio2" value="false">
							          否
							  </label>
						</div>
				  </div>
		  </div>
		  <!-- JDBC输出 -->
		  <div class="container-output-jdbc" style="display: none;">
		  		   <div class="form-group">
				   		<label class="col-sm-2 control-label">数据源地址:</label>
				   		<div class="col-sm-5">
					      <input name="jdbcUrl" class="form-control" placeholder="jdbcUrl">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">用户名:</label>
				   		<div class="col-sm-5">
					      <input name="username" class="form-control" placeholder="userName">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">密码:</label>
				   		<div class="col-sm-5">
					      <input name="password" class="form-control" placeholder="passWord">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">表名:</label>
				   		<div class="col-sm-5">
					      <input name="tableName" class="form-control" placeholder="tableName">
					    </div>
				  </div>
				   <div class="form-group">
				   		<label class="col-sm-2 control-label">批量大小:</label>
				   		<div class="col-sm-5">
					      <input name="batchSize" class="form-control" placeholder="batchSize">
					    </div>
				  </div>
		  </div>
		  <!-- mongo输出 -->
		  <div class="container-output-db" style="display: none;">
		  		   <div class="form-group">
				   		<label class="col-sm-2 control-label">主机地址:</label>
				   		<div class="col-sm-5">
					      <input name="host" class="form-control" placeholder="host">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">端口:</label>
				   		<div class="col-sm-5">
					      <input name="port" class="form-control" placeholder="port">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">数据库名称:</label>
				   		<div class="col-sm-5">
					      <input name="dbName" class="form-control" placeholder="dbName">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">表名:</label>
				   		<div class="col-sm-5">
					      <input name="tableName" class="form-control" placeholder="tableName">
					    </div>
				  </div>
				  <div class="form-group">
				   		<label class="col-sm-2 control-label">批量大小:</label>
				   		<div class="col-sm-5">
					      <input name="batchSize" class="form-control" placeholder="batchSize">
					    </div>
				  </div>
		  </div>
</div>
<jsp:include page="/foot.jsp"/>
    
    
    <!--DEVEL-->
	<script src="${ctx }/editor/lib/codemirror.js"></script>
	<script src="${ctx }/editor/addon/dialog/dialog.js"></script>
	<script src="${ctx }/editor/addon/search/searchcursor.js"></script>
	<script src="${ctx }/editor/mode/clike/clike.js"></script>
	<script src="${ctx }/editor/addon/edit/matchbrackets.js"></script>
	<script src="${ctx }/editor/keymap/vim.js"></script>
	<script src="${ctx }/editor/addon/display/fullscreen.js"></script>
	<script src="${ctx }/editor/mode/python/python.js"></script>
	<script src="${ctx }/editor/mode/javascript/javascript.js"></script>
	
	<script src="${ctx }/js/beautify.js"></script>
	
	<script src="${ctx }/js/config_setting.js"></script>
	<!-- 任务Job JS配置 -->
	<script src="${ctx }/js/job/job_input_config.js"></script>
	<script src="${ctx }/js/job/job_output_config.js"></script>
	<script>
		var parse = CodeMirror.fromTextArea(document.getElementById("parse"), {
			lineNumbers : true,
			mode : "python",
			matchBrackets : true,
		});

		
		var input = CodeMirror.fromTextArea(document.getElementById("input"), {
			lineNumbers : true,
			mode : "javascript",
			matchBrackets : true,
		});
		
		var output = CodeMirror.fromTextArea(document.getElementById("output"), {
			lineNumbers : true,
			mode : "javascript",
			matchBrackets : true,
			//theme : "monokai",
		});
		
			
        $("#publish_job").click(function(){
			
			$("#parse").text(parse.getValue()) ;
			$("#input").text(input.getValue()) ;
			$("#output").text(output.getValue()) ;
			
			$.post("${ctx }/admin/job/${_jobType}/save_or_update", $("#job_form").serialize(), function(result) {
				if(result.ok){
					bootbox.alert("保存成功",function(){
						location.href = "${ctx}/admin/job/get/"+$("#name").val() ;
					});
					
				}else{
					bootbox.alert("保存失败:"+result.message);
				}
				
			}, "json").error(function(result) {
				bootbox.alert("保存失败,无响应!");
			});
		}) ;
        
        
		$("#reset_job").click(function(){
			
			$.post("${ctx }/admin/job/reset/"+$("#name").val(),function(result) {
				if(result.ok){
					bootbox.alert("重置成功");
					
				}else{
					bootbox.alert("重置失败:"+result.message);
				}
				
			}, "json").error(function(result) {
				bootbox.alert("重置失败,无响应!");
			});
		}) ;
		
		
		
        var tempUri = null ;
        
		$("#test_job").click(function(){
			$("#parse").text(parse.getValue()) ;
			$("#input").text(input.getValue()) ;
			$("#output").text(output.getValue()) ;
			
			bootbox.dialog({
		        title: "测试",
		        onEscape: true ,
		        message: '<div class="row className">  ' +
		          '<div class="col-md-12"> ' +
		          '<form class="form-horizontal" id="uri-form"> ' +
		          '<div class="form-group"> ' +
		          '<label class="col-md-2 control-label" for="name">测试地址</label> ' +
		          '<div class="col-md-8"> ' +
		          '<input id="uri" name="uri" type="text" placeholder="uri" class="form-control input-md"> ' +
		          '</div> ' +
		          '</div> ' +
		          '</form> ' +
		          
		          '<div class="form-group"> ' +
		          '<label class="col-md-2 control-label" for="name">返回结果</label> ' +
		          '<div class="col-md-8"> ' +
		          '<textarea style="width:100%;height:500px;word-wrap:normal" id="test_result"></textarea>' +
		          '</div> ' +
		          '</div> ' +
		          
		          
		          '</div> </div>' +
		          '</form> </div>  </div>',
		        size: 'large',
		        buttons: {
		          button: {
		            label: "测试",
		            callback: function() {
		            	$("#test_result").text("开始采集清耐心等待......") ;
		            	$.post("${ctx }/admin/job/${_jobType}/test", $("#job_form,#uri-form").serialize(), function(result) {
		            		var opts= {} ;
		            		opts.wrap_line_length = 20;
		            		$("#test_result").text(js_beautify(result.message,opts)) ;
		    			}, "json").error(function(result) {
		    				bootbox.alert("测试失败,无响应!");
		    			});
		            	tempUri = $("#uri").val() ; 
		            	return false ;
		            }
		          }
		        }
		      }
		    );
			
			
			if(tempUri!=null){
				$("#uri").val(tempUri) ;
			}
			
		}) ;
		
	</script>
  </body>
</html>
